<template>
  <div id="container" style="background: #F5F5F7; height: 100%;">
    <div class="header-content">
      <span class="go-back" @click="handleGoBackHome"><a-icon type="left" /> 返回</span>
      <span class="hospital-title"><img :src="this.$route.query.hosLogo" />{{ this.$route.query.hosName }}
        <span style="padding: 0 10px;">|</span>
        {{ this.$route.query.departmentName }}</span>
    </div>
    <div class="body-content">
      <div class="banner-content">
        <div class="doctor-info">
          <div class="doctor-name"><b>{{ doctorInfo.docName }}<span>{{ doctorInfo.jobTitle }}</span></b></div>
          <div class="doctor-tag">
            <div class="tags" v-for="(item, index) in doctorInfo.labelName" :key="index">{{ item }}</div>
          </div>
          <div class="doctor-skill">擅长：{{ doctorInfo.skill }}</div>
        </div>
        <div v-if="this.$route.query.bustUrl" class="doctor-img"><img :src="this.$route.query.bustUrl" width="100%" />
        </div>
      </div>
      <div class="date-content">
        <div v-for="(item, index) in dateData" :key="index" class="date-item" :class="{ active: dateIndex == index }"
          @click="handleDate(index, item)">
          <div>{{ item.week }} {{ item.scheduleDate }}</div>
          <div>
            {{ item.scheduleStatus === 1 ? '有号' : item.scheduleStatus === 2 ? '约满' : item.scheduleStatus === 3 ? '无号' : item.scheduleStatus === 4 ? '停诊' : item.scheduleStatus === 10 ? '即将放好' : '未知' }}
          </div>
        </div>
      </div>
      <div class="visit-content">
        <div class="time-content">
          <div class="time" v-for="(item, index) in timeData" :key="index" :class="{ active: timeIndex == index }"
            @click="handleTime(index, item)">
            <img
              v-if="timeIndex == index && (item.afternoon === '上午' || item.afternoon === '下午' || item.afternoon === '全天')"
              src="@/assets/sonA.png" width="23%" />
            <img
              v-else-if="timeIndex !== index && (item.afternoon === '上午' || item.afternoon === '下午' || item.afternoon === '全天')"
              src="@/assets/sonB.png" width="23%" />
            <img v-else-if="timeIndex == index && (item.afternoon === '夜诊')" src="@/assets/moonA.png" width="23%" />
            <img v-else-if="timeIndex !== index && (item.afternoon === '夜诊')" src="@/assets/moonB.png" width="23%" />
            {{ item.afternoon }}
          </div>
        </div>
        <div class="scheduling-list">
          <div class="item" v-for="item in numberSource" :key="item.timeSpan">
            <span style="padding-left: 25px; color: #000;">{{ item.timeSpan }}</span>
            <a-divider type="vertical" />
            <span style="color: #1971FF;">剩余：{{ item.remainCount }}</span>
            <div style="float: right;">
              <span v-if="item.fee" style="color: #FC2249; font-size: 20px;">¥ {{ item.fee }}</span>
              <span v-else style="color: #FC2249; font-size: 20px;"></span>
              <span v-if="item.sourceStatus === 1" @click="handleReservation" class="reservation"
                style="background: #1971ff;">预约</span>
              <span v-else-if="item.sourceStatus === 2" @click="handleReservation" class="reservation"
                style="background: #FC2249;">约满</span>
              <span v-else-if="item.sourceStatus === 3" @click="handleReservation" class="reservation"
                style="background: #FC2249;">无号</span>
              <span v-else-if="item.sourceStatus === 4" @click="handleReservation" class="reservation"
                style="background: #AAAAAA;">停诊</span>
              <span v-else-if="item.sourceStatus === 10" @click="handleReservation" class="reservation"
                style="background: #FC2249;">即将放号</span>
              <span v-else @click="handleReservation" class="reservation" style="background: #FC2249;">未知</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div id="bbox" ref="bbox">
      <a-modal centered v-model="isSHowMark" :zIndex="1001" :footer="null" width="280px"
        :getContainer="() => $refs.bbox">
        <template slot="closeIcon">
          <img style="margin-top: -10px; margin-right: -10px" src="../assets/close-icon.png" width="24" />
        </template>
        <div class="RQCode-img">
          <img :src="doctorInfo.qrCodeUrl" alt="医生二维码" />
        </div>
        <div class="modle-reservation"><b>微信扫描立即预约</b></div>
        <div class="modle-doctor-name">{{ doctorInfo.docName }} {{ doctorInfo.jobTitle }}</div>
      </a-modal>
    </div>

  </div>
</template>

<script>
import { getQueryQrCode, getDataList, getOneDayScheduleList, getSource } from "../api/home";
import Vue from 'vue'
import VueLazyload from 'vue-lazyload'
import { dataSource } from "./mock.js";
import Card from './component/Card'
Vue.use(VueLazyload)
// import ref from 'vue';

// const boxs = ref();
export default {
  name: "home",
  components: {
  },
  data() {
    return {
      isSHowMark: false,
      doctorId: this.$route.query.id, // 医生ID
      dataSource: dataSource,
      dateIndex: 0,
      timeIndex: 0,
      // 医生信息
      doctorInfo: {
        departmentId: 0,
        docName: '',
        id: 0,
        jobTitle: '',
        labelName: '',
        logo: '',
        qrCodeUrl: '',
        skill: '',
      },
      dateData: [
      ],
      timeData: [
      ],
      numberSource: [],
    }
  },
  created() {
    window.scrollTo(0, 0)
    // console.log(this.$route.query.id)
    this.getDoctorInfo(this.$route.query.doctorId);
    this.getDataList(); // 获取排班信息
  },
  watch: {

  },
  methods: {
    handleDate(index, item) {
      this.timeIndex = 0;
      this.dateIndex = index;
      this.getOneDayScheduleList(item.scheduleDate);
    },
    handleTime(index, data) {
      this.timeIndex = index;
      this.getSource(data.platformScheduleId);
    },

    getDoctorInfo(doctorId) {
      getQueryQrCode({
        doctorId: doctorId
      }).then(res => {
        if (res.code === 200) {
          console.log('=====', res)
          var dataSource = res.result;
          if (dataSource.labelName) {
            dataSource.labelName = dataSource.labelName.split(',');
          }
          this.doctorInfo = dataSource;
        }
      })
    },

    getDataList() {
      getDataList({
        "hosId": this.$route.query.hosId,
        "doctorId": this.$route.query.doctorId,
        "secondDepartmentId": this.$route.query.secondDepartmentId,
      }).then(res => {
        if (res.code === 200) {
          this.dateData = res.result;
          if (res.result.length) {
            this.getOneDayScheduleList(res.result[0].scheduleDate);
          }
        }
      })
    },

    getOneDayScheduleList(data) {
      getOneDayScheduleList({
        "hosId": this.$route.query.hosId,
        "doctorId": this.$route.query.doctorId,
        "secondDepartmentId": this.$route.query.secondDepartmentId,
        "scheduleDate": data
      }).then(res => {
        if (res.code === 200) {
          // timeData
          var timeData = [];
          if (res.result) {
            res.result.forEach(item => {
              if (item.scheduleCategory === 1) {
                timeData.push({
                  afternoon: '上午',
                  platformScheduleId: item.platformScheduleId,
                });
              } else if (item.scheduleCategory === 2) {
                timeData.push({
                  afternoon: '下午',
                  platformScheduleId: item.platformScheduleId,
                });
              } else if (item.scheduleCategory === 3) {
                timeData.push({
                  namafternoone: '全天',
                  platformScheduleId: item.platformScheduleId,
                });
              } else if (item.scheduleCategory === 4) {
                timeData.push({
                  namafternoone: '夜间',
                  platformScheduleId: item.platformScheduleId,
                });
              }
            });
            this.timeData = timeData;

            if (res.result) {
              this.getSource(res.result[0].platformScheduleId);
            }
          }
        }
      })
    },

    getSource(data) {
      getSource({
        "platformScheduleId": data,
      }).then(res => {
        if (res.code === 200) {
          console.log("=============", res)
          this.numberSource = res.result;
        }
      })
    },

    handleReservation() {
      this.isSHowMark = true;
    },
    handleClose() {
      this.isSHowMark = false;
    },


    handleGoBackHome() {
      this.$router.back()
    },



    // chagneRefresh() {
    //   window.location.reload()
    // },



  }
};
</script>

<style scoped>
#container /deep/ .ant-modal-content {
  border-radius: 10px !important;
}
#container >>> .ant-modal-content {
  border-radius: 10px !important;
}
#container >>> .ant-modal {
  border-radius: 10px !important;
}
.header-back-content {
  width: 100%;
  height: 100px;
  margin-top: 90px;
  line-height: 100px;
  /* background: red; */
  overflow: hidden;
}
.go-back {
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  width: 60px;
  float: left;
  text-align: left;
  margin-left: 20px;
}
.hospital-title {
  margin-left: -60px;
  font-size: 18px;
  font-weight: 500;
  color: #000;
}
.hospital-title img {
  width: 50px;
  height: 50px;
  margin-right: 10px;
}
.body-content {
  width: 1280px;
  margin: 110px auto;
}
.banner-content {
  width: 100%;
  height: 400px;
  background-image: url("../assets/banner.png");
  background-size: 100%;
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 10px;
}
.doctor-info {
  float: left;
  padding: 60px 0 0 0px;
  width: 540px;
  margin-left: 150px;
}
.doctor-name {
  font-size: 55px;
  color: #0c2754;
  margin-bottom: 20px;
  font-weight: bold;
}
.doctor-name span {
  font-size: 26px;
  padding-left: 15px;
  color: #506587;
  font-weight: 500;
}
.doctor-tag {
  overflow: hidden;
  margin-bottom: 10px;
}
.doctor-tag .tags {
  padding: 8px 15px;
  background: #ecf3ff;
  color: #1971ff;
  float: left;
  margin: 0 10px 10px 0;
  border-radius: 4px;
}
.doctor-skill {
  font-weight: 500;
  color: #19191a;
  line-height: 22px;
  font-size: 16px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doctor-img {
  float: right;
  width: 340px;
  height: 400px;
  margin-right: 150px;
}
.doctor-img img {
  height: 400px;
  border: none;
}
.date-content {
  height: 70px;
  padding-left: 40px;
  background: #fff;
  margin-bottom: 10px;
  border-radius: 8px;
  width: 100%;
  overflow: hidden;
  overflow-x: auto;
  white-space: nowrap;
}
.date-item {
  text-align: center;
  /* margin: 0 30px; */
  margin-right: 60px;
  cursor: pointer;
  padding-top: 20px;
  color: #7e7f80;
  font-weight: 600;
  padding-bottom: 6px;
  display: inline-block;
}
.date-item:hover {
  color: #1971ff;
  border-bottom: 2px solid #1971ff;
}
.date-content .active {
  color: #1971ff;
  border-bottom: 2px solid #1971ff;
  font-weight: 600;
}
.visit-content {
  height: 500px;
  background: #fff;
  border-radius: 8px;
  min-height: 500px;
  margin-bottom: 30px;
}
.time-content {
  width: 340px;
  margin: 0 auto;
  height: 80px;
}
.time-content .time {
  width: 90px;
  height: 40px;
  line-height: 40px;
  margin-right: 20px;
  cursor: pointer;
  margin-top: 20px;
  border-radius: 6px;
  color: #333;
  background: #f7f8fa;
  float: left;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
}
.time-content .time img {
  margin-top: -3px;
}
.time-content .active {
  background: #1971ff;
  color: #fff;
}
.time-content .time:hover {
  background: #1971ff;
  color: #fff;
}
.scheduling-list {
  overflow: hidden;
}
.scheduling-list .item {
  width: 600px;
  height: 50px;
  line-height: 50px;
  font-weight: 600;
  background: #f7faff;
  border-radius: 8px;
  float: left;
  margin: 0 20px 15px 20px;
  font-size: 16px;
}
.reservation {
  display: inline-block;
  width: 92px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  font-weight: 400;
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  margin: 0 25px;
}

.RQCode-img {
  width: 170px;
  height: 170px;
  line-height: 170px;
  text-align: center;
  margin: 0px auto 0;
}
.RQCode-img img {
  width: 170px;
  height: 170px;
}
.modle-reservation {
  text-align: center;
  margin: 12px 0 3px;
  color: #000;
  font-weight: bold;
}
.modle-doctor-name {
  text-align: center;
  font-weight: bold;
  color: red;
  margin-bottom: 0px;
}

.header-content {
  width: 100%;
  height: 80px;
  line-height: 80px;
  background-repeat: no-repeat;
  background-color: #fff;
  position: fixed;
  top: 0;
  text-align: center;
  box-shadow: 0px 3px 4px 0px rgba(140, 130, 130, 0.09);
}
</style>
